﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace NibbleOil.Web.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        { 
        }

        protected void LoginUser_LoggingIn(object sender, LoginCancelEventArgs e)
        {
            Business.Model.USUARIO oUser = Business.Helper.User.ValidateUser(LoginUser.UserName, LoginUser.Password);
            if (oUser != null)
            {
                Session.Add("User", oUser);
                FormsAuthentication.SetAuthCookie(LoginUser.UserName, true);               
                Response.Redirect("~/authentication/Default.aspx");
            }
            else
            {
                CustomValidator1.ErrorMessage = "Email o Clave inválidos.";
                CustomValidator1.IsValid = false;
                CustomValidator1.Visible = false;
            }
        }
    }
}
